;
define(function (required, exports, modules) {
    var modal = require('mods/modal')
    exports.commission_dowm = function (ols) {
        $("." + ols).dropdown({
            on: "hover"
        });


        $('.dropdown').change(function () {
            var recommend_id = $('input[name=recommend-id]').val()
            var _csrf = $('#csrf').val()
            if (!isNaN(recommend_id)) {
                $.ajax({
                    url: '/admin/recommend/set-commission',
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        recommend_id: recommend_id,
                        _csrf: _csrf
                    },
                    success: function (res) {
                        if (res.code == 200) {
                            console.log(res.data);
                            var data = res.data
                            $('input[name=member-name]').val(data.member_name)
                            $('input[name=recommend-name]').val(data.recommend_name)
                        } else {
                            modal.alert(res.msg)
                            return false
                        }
                    }
                })
            }
        })
    }

    exports.commission_set = function () {
        $('.commission-save').click(function () {
            var _that = $(this)
            modal.confirm('请认真核对数据,一旦生产不能修改,确定要生成吗?', {}, function () {
                if (_that.hasClass('disabled')) {
                    modal.msg('系统正在处理中~~~,请不要重复请求')
                    return false
                }

                var recommend_id = $('input[name=recommend-id]').val()
                var recommend_commission = $('input[name=recommend-commission]').val()
                var _csrf = $('#csrf').val()

                if (isNaN(recommend_commission)) {
                    modal.msg('请填写正确的佣金')
                    return false
                }
                if (recommend_commission.length < 1 || recommend_commission < 1) {
                    modal.msg('请填写正确的佣金数额')
                    return false
                }
                _that.addClass('disabled')
                $.ajax({
                    url: '/admin/recommend/set-commission',
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        recommend_id: recommend_id,
                        recommend_commission: recommend_commission,
                        func: 'set_commission',
                        _csrf: _csrf
                    },
                    success: function (res) {
                        _that.removeClass('disabled')
                        if (res.code == 200) {
                            modal.msg(res.msg, {}, function () {
                                window.location.href = '/admin/recommend/commission'
                            })
                        } else {
                            modal.alert(res.msg)
                            return false
                        }
                    }
                })

            }, function () {
            })


        })
    }

    exports.commission_del = function () {
        $('._del').click(function () {
            var recommend_id = $(this).attr('data-id')
            var commission_status = $(this).attr('data-status')
            var _csrf = $('#csrf').val()
            if (commission_status != '2') {
                modal.msg('此笔佣金还没有发放,不能删除')
                return false
            }

            modal.confirm('确定要删除吗?', {}, function () {
                $.ajax({
                    url: '/admin/recommend/ops',
                    type: "POST",
                    dataType: 'json',
                    data: {
                        recommend_id: recommend_id,
                        _csrf: _csrf
                    },
                    success: function (res) {
                        if (res.code == 200) {
                            modal.msg(res.msg, {}, function () {
                                window.location.reload()
                            })
                        } else {
                            modal.alert(res.msg)
                            return false
                        }
                    }
                })
            }, function () {
            })
        })
    }

    exports.commission_editor = function () {
        $('.recommend_status').click(function () {
            var recommend_id = $(this).attr('data-id')
            var commission_status = $(this).attr('data-status')
            var recommend_log = $(this).attr('data-recommend')
            var _csrf = $('#csrf').val()
            if (commission_status == '2') {
                modal.msg('此佣金已经发放')
                return false
            }

            if (commission_status == '0') {
                modal.msg('请先修改佣金,确定是否发放')
                return false
            }

            $.ajax({
                url: '/admin/recommend/editor',
                type: "POST",
                dataType: 'json',
                data: {
                    recommend_id: recommend_id,
                    _csrf: _csrf,
                    commission_status: commission_status,
                    recommend_log_id: recommend_log
                },
                success: function (res) {
                    if (res.code == 200) {
                        modal.msg(res.msg, {}, function () {
                            window.location.reload()
                        })
                    } else {
                        modal.alert(res.msg)
                        return false
                    }
                }
            })

        })
    }


})